package com.sky.controller.user;


import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController("用户套餐")
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "用户套餐功能")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    @ApiOperation("用户套餐查询")
    @GetMapping("/list")
    public Result<List<SetmealVO>> list(Long categoryId) {
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
        List<SetmealVO> setmealVOList = setmealService.listWithDish(setmeal);
        return Result.success(setmealVOList);
    }
    @ApiOperation("根据套餐id查询包含的菜品列表")
    @GetMapping("/dish/{id}")
    public  Result<List<DishItemVO>> dishList(@PathVariable Long id) {
        log.info("id为{}",id);
        List<DishItemVO> dishItemVOList = setmealService.getDishItemById(id);
        return Result.success(dishItemVOList);
    }
}
